﻿using System.ComponentModel;
using Android.Content;
using Android.Content.Res;
using Android.Graphics.Drawables;
using Android.Graphics.Drawables.Shapes;
using Android.Support.V4.Content;
using Android.Text;
using Android.Views;
using JWXH.XH.components;
using JWXH.XH.Droid.components;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using Color = Android.Graphics.Color;

[assembly: ExportRenderer(typeof(EntryNoBorder), typeof(EntryNoBorderRender))]
namespace JWXH.XH.Droid.components
{
    public class EntryNoBorderRender : EntryRenderer
    {
        public EntryNoBorderRender(Context context) : base(context)
        {
        }

        protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
        {
            base.OnElementChanged(e);
            if (Control != null)
            {
                Control.Background = ContextCompat.GetDrawable(Context, Resource.Drawable.edittext_noborder);
                //                this.Background = ContextCompat.GetDrawable(Context, Resource.Drawable.edittext_noborder);
            }

        }

        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            if (Control != null)
            {
                var gd = (Control.Background as GradientDrawable);
                var cusBorderColor = (sender as EntryNoBorder).CusBorderColor;
                if (!string.IsNullOrEmpty(cusBorderColor)) gd.SetStroke(1, Color.ParseColor(cusBorderColor));
                this.Control.Background = gd;
            }
        }
    }
}